//引入mutations的常量
import { SET_CATEGORYLIST_STATE } from "../module_type"
//引入请求三级分类列表数据的方法
import { getCategoryList } from "@/api"

const state = {
  //定义三级分类列表
  categoryList: [],
}
const mutations = {
  //设置列表的值
  [SET_CATEGORYLIST_STATE](state, payload) {
    state.categoryList = payload.categoryList
  },
}
const actions = {
  //异步请求三级列表数据
  async reqCategoryList({ commit }) {
    try {
      const res = await getCategoryList()
      commit(SET_CATEGORYLIST_STATE, { categoryList: res })
    } catch (error) {
      alert(error.message)
    }
  },
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
}
